'use strict';

import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'

export function getPcode(orgId) {
    return dispatch => basicAction({
        type: 'get',
        dispatch: dispatch,
        actionType: 'GET_PCODE',
        url: `${ApiTable.getPcode}`,
        msg: { error: '获取水环境pcode失败' },
    });
}

export function waterLogin(data) {
    return dispatch => basicAction({
        type: 'post',
        data: { url: 'login', method: 'post' },
        dispatch: dispatch,
        actionType: 'POST_WATER_LOGIN',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '登录水环境失败' },
        // reducer: { name: 'members' }
    });
}

export function getWaterLevelTrend(query) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getWaterLevelTrend}?token=${query?.token}&orgId=${query?.orgId}&keyword=`,
        },
        dispatch: dispatch,
        actionType: 'GET_WATER_LEVEL_TREND',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '获取水位趋势失败' },
    });
}

export function getWaterStructures(query) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getWaterStructures}?token=${query?.token}`,
        },
        dispatch: dispatch,
        actionType: 'GET_WATER_STRUCTURES',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '获取水务结构物失败' },
    });
}

export function getWaterVideoList(struIds, query) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getWaterVideoList.replace('{struIds}', struIds)}&token=${query?.token}`,
        },
        dispatch: dispatch,
        actionType: 'GET_WATER_VIDEO_LIST',
        url: `${ApiTable.getSmartWaterData.replace('{struIds}', struIds)}`,
        msg: { error: '获取水务视频失败' },
    });
}

export function getYsAccessToken(query) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getYsAccessToken}?token=${query?.token}`,
        },
        dispatch: dispatch,
        actionType: 'GET_YS_ACCESS_TOKEN',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '获取萤石授权失败' },
    });
}

export function getWaterAlarms(query) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getWaterAlarms}&token=${query?.token}`,
            method: 'post',
            data: { "keywords": "", "status": "new", "levels": [1, 2, 3], "orderBy": "endTime", "orderDirection": "desc", "limit": 10, "offset": 0, "structures": null, "types": [1] }
        },
        // data: { "structures": null, "orderBy": "endTime", "endTime": "2022-06-30 23:59:59", "keywords": "", "levels": [1, 2, 3], "startTime": "2022-06-01 00:00:00", "orderDirection": "desc", "status": "history", "offset": 0, "types": [1], "limit": 10 },
        dispatch: dispatch,
        actionType: 'GET_WATER_ALARMS',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '获取告警失败' },
    });
}

export function getPumpStatus(structId) {
    return dispatch => basicAction({
        type: 'post',
        data: {
            url: `${ApiTable.getPumpStatus.replace('{structId}', structId)}`,
        },
        dispatch: dispatch,
        actionType: 'GET_PUMP_STATUS',
        url: `${ApiTable.getSmartWaterData}`,
        msg: { error: '获取水泵状态失败' },
    });
}